package com.mmp.main.util;

import com.mmp.common.util.Common;
import com.mmp.main.entity.HospitalDevice;

public class HtmlUtil {

	public static String[] getPPMVisitMonths(HospitalDevice hd) {
		if (hd != null) {
			String pmVisitsMonths = hd.getPmVisitsMonths();
			if (pmVisitsMonths != null)
				return Common.getConcatenatedValues(pmVisitsMonths, true);
		}
		return new String[0];
	}

	public static String getMonthesAsHtmlSelect(String name, String cssClassName) {
		String html = "<select id='" + name + "' name='" + name + "'";

		if (cssClassName != null && !cssClassName.trim().isEmpty())
			html += "class='" + cssClassName + "'";

		html += ">";
		Enums.YEAR_MONTHS[] items = Enums.YEAR_MONTHS.values();
		for (Enums.YEAR_MONTHS i : items)
			html += "<option value='" + i.getId() + "'>" + i.getText() + "</option>";
		html += "</select>";
		return html;
	}

	public static String getDevicePPMVisitMonthesAsHtmlSelect(String name, HospitalDevice device) {
		String html = "<select id='" + name + "' name='" + name + "'>";
		String[] ppmMonths = getPPMVisitMonths(device);
		if (ppmMonths != null)
			for (String m : ppmMonths)
				html += "<option value='" + m + "'>" + Enums.YEAR_MONTHS.getTextById(m) + "</option>";
		html += "</select>";
		return html;
	}

	public static String arrayFromJavaToJavaScript(String[] javaAry) {
		String jsAry = "";
		if (javaAry != null && javaAry.length > 0) {
			jsAry += "['" + javaAry[0] + "'";
			for (int i = 1; i < javaAry.length; i++)
				jsAry += ",'" + javaAry[i] + "'";
			jsAry += "]";
			return jsAry;
		}

		return "[]";
	}

	public static String arrayFromJavaToJavaScript(String concatenatedString) {
		return arrayFromJavaToJavaScript(Common.getConcatenatedValues(concatenatedString, false));
	}

	// $("form").validate({ignore:"*"});
	public static String getResetButtonHTML() {
		return "<input type='button' id='biomedapp_return_btn' value='رجوع بدون حفظ' onclick='returnToWelcomePage()' class='pure-skin-mine pure-button-primary' >";
	}

	public static String getSaveThenReturnButtonHTML() {
		// 
		return "<input type='button' class='pure-skin-mine pure-button-primary'  onclick='_onClickJobOrderFollowupSaveBtn()' name='" + Default.SAVE_THEN_RETURN_BTN_NAME + "' value='حفظ' style='width:80px'>";
	}

	public static String getSaveThenContinueButtonHTML() {
		return "<input id='" + Default.SAVE_THEN_CONTINUE_BTN_NAME + "' type='submit' name='"
				+ Default.SAVE_THEN_CONTINUE_BTN_NAME + "' value='حفظ  ومتابعة' style='width:120px'>";
	}

	public static String getSaveThenGoBackButtonHTML() {
		return "<input type='submit' name='" + Default.SAVE_THEN_GO_BACK_BTN_NAME
				+ "' value='الإجراء السابق' formnovalidate style='width:120px'>";
	}

	public static String showUploadedFilesInViewMode(String concatenatedStr, boolean sort) {

		String[] fNames = Common.getConcatenatedValues(concatenatedStr, sort);

		if (fNames != null && fNames.length != 0) {

			StringBuffer html = new StringBuffer();

			for (String fName : fNames)
				html.append("<a class='attach_link' href=\"javascript:viewFile('" + fName + "')\">"
						+ fName.substring(fName.lastIndexOf("_") + 1) + "</a>");

			return html.toString();

		}

		return "لا يوجد";
	}

	public static String getBooleanAsString(Boolean b) {
		if (b == null)
			return "لم يحدد";
		return (b) ? "نعم" : "لا";
	}
}
